//
//  CLHelpAndSet.m
//  CareLink
//
//  Created by clinging on 16/8/20.
//  Copyright © 2016年 Seven Team. All rights reserved.
//

#import "CLHelpAndSet.h"

#import "CLUserFeedBackViewController.h"
#import "CLSeverController.h"
#import "CLAlterController.h"

@interface CLHelpAndSet ()

@end

@implementation CLHelpAndSet

//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        return [super initWithStyle:UITableViewStyleGrouped];
//    }
//    return self;
//}
//



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    //把导航控制器设置回去
    [[[self.navigationController.navigationBar subviews]objectAtIndex:0]setAlpha:1.0];
    self.navigationItem.title = @"设置与帮助";
   
   }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *Id = @"CLHelpAndfSetCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Id];
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (!cell) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Id];
    }
    
    if (indexPath.row == 0) {
        
        cell.textLabel.text = @"意见反馈";
        
//        UISwitch *switcher = [[UISwitch alloc] init];
        
//        cell.accessoryView = switcher;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        
    } else if(indexPath.row == 1) {
        
        cell.textLabel.text = @"加号服务说明";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        
    } else if(indexPath.row == 2) {
        
        cell.textLabel.text = @"修改密码";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//        
//    } else if(indexPath.row == 3) {
//        
//        cell.textLabel.text = @"用户协议";
//        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
   }
        else {

        
        cell.textLabel.text = @"退出账号";
//        cell.textLabel.textColor = [UIColor redColor];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    
    }
    
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    
//    if (indexPath.section == 0 && indexPath.row == 0)
//    {
//        CLidea * ideaVC = [[CLidea alloc]init];
//        ideaVC.hidesBottomBarWhenPushed = YES;
//        ideaVC.navigationItem.title = @"意见反馈";
//        
//        [self.navigationController pushViewController:ideaVC animated:YES];
//        
//    }
    
    if(indexPath.row == 0)
    {
    
    [self.navigationController pushViewController:[[CLUserFeedBackViewController alloc]init] animated:YES];
        NSLog(@"%@",self.navigationController);
    
    }
    
    else if (indexPath.row == 1)
    {
        
        // 弹出提醒框
        UILabel *downLabel = [[UILabel alloc] init];
        // 设置背景颜色
        downLabel.backgroundColor = [UIColor blackColor];
        // 设置文字居中
        downLabel.textAlignment = NSTextAlignmentCenter;
        // 设置文字颜色
        downLabel.textColor = [UIColor redColor];
              // 计算frame
        //        CGFloat downW = 120;
        //        CGFloat downH = 80;
        //        // 设置label的位置
        //        downLabel.center =  self.view.center;
        //        downLabel.bounds = CGRectMake(0, 0, downW, downH);
        
        downLabel.frame = CGRectMake(120, 140, 100, 600);
        
        
        // 设置透明度
        downLabel.alpha = 0;
        // 把label添加到控制器的view上
        [self.view addSubview:downLabel];
        
        [self.navigationController pushViewController:[[CLSeverController alloc]init] animated:YES];

        
//        // 开启一个2秒的动画,让label慢慢的显示出来
//        [UIView animateWithDuration:1.0 animations:^{
//            // 设置label的透明度,让它慢慢显示
//            downLabel.alpha = 0.7;
//        } completion:^(BOOL finished) { // 2秒的动画执行完成之后需要做的事情
//            
//            // 开启一个延迟2秒之后再去执行的动画,此动画持续时间为2秒,动画匀速执行
//            // UIViewAnimationOptionCurveLinear 匀速
//            [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
//                // 设置label的透明度,让它慢慢的不显示
//                downLabel.alpha = 0;
//            } completion:^(BOOL finished) { // 动画执行完成之后去做的事情
//                // 把label从它的父控件中移除
//                [downLabel removeFromSuperview];
//            }];
//        }];
//        
        
        
    }
    else if (indexPath.row == 2)
    {
        
        [self.navigationController pushViewController:[[CLAlterController alloc]init] animated:YES];
    }
    else if (indexPath.row == 3)
    {
        
        
        //        NSLog(@"注销");
        
        
        // 提示
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"是否注销" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//        // 取消按钮
//        
        UIAlertAction *cancleBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            
//
//            
//            
       }];
        
//        
        // 按钮
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
            //注销后偏好设置保存未登录状态
            [self clearLoginState];
            // 发布通知 跳转控制器
            [[NSNotificationCenter defaultCenter] postNotificationName:@"CLNoLeftBtnBackClick" object:nil];
            
            [self.navigationController popToRootViewControllerAnimated:YES];
            
            
        }];
        
        // 添加按钮
        [alertVc addAction:confirm];
        
        [alertVc addAction:cancleBtn];
        
        // 显示提示框
        [self presentViewController:alertVc animated:YES completion:nil];
        
        return;
        
        
        
    }
    
}
//- (void)buttonClick:(UIButton *)sender{
//    
//           
//        [self.navigationController pushViewController:[[CLidea alloc]init] animated:YES];
//        
//    }
//- (void)buttonClick:(UIButton *)sender
//{
//    
//    if (sender.tag == 100)
//    {
//        
//        [self.navigationController pushViewController:[[CLUserFeedBackViewController alloc]init] animated:YES];
//        
//    }
//    
//}


//注销后偏好设置保存未登录状态
-(void)clearLoginState{
    
    //创建default对象
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL isLoad = NO;
    //存储数据
    [userDefault setBool:isLoad forKey:@"isLoad"];
    //立即同步
    [userDefault synchronize];
    
}

@end
